Byteasar loved to play with building blocks as a child.
He used to arrange the blocks into
columns of random height
and then organize them in the following manner:
Byteasar would choose a number
and try to arrange the blocks in such a way that
some
consecutive columns would be of equal height. Furthermore he always tried to
achieve this goal in a minimum number of moves possible, where a single move consists in:
However, Byteasar was never quite sure if his sequence of moves was indeed optimal, therefore he has asked you to write a programme that will help him solve the problem.
Write a programme that:
along with the initial setup of the blocks from the standard input,
In the first line of the standard input there are
two integers,
and
(
), separated by a single space.
Each of the following
lines contains the height of some column;
the line no.
contains the integer
- the height of the
column,
ie. the number of blocks it consists of.
The optimal solution should be written out to the standard output, ie. such arrangement of blocks that:
consecutive columns of equal height,
lines, each one containing a single integer.
The number in the first line should be the minimum number of moves needed to get
the desired arrangement.
The line no.
(for
) should contain the number
-
the final height of the
column.
If more than one optimal solution exists, write out one chosen arbitrarily.
For the input data:
5 3 3 9 2 3 1
the correct result is:
2 3 9 2 2 2
Task author: Tomasz Walen.
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.